<?php
namespace Controller;

use Model;

class Member extends Controller {
	private $MMember = NULL;

	public function __construct() {
		$this->MMember = Model\Member::getInstance();
	}

	public function index() {
		$this->display();
	}

	public function member() {
		$pager = $this->MMember->member($_GET['page']);
		
		echo "<br />当前第&nbsp;{$pager->current}&nbsp;页&nbsp;";
		
		if ($pager->back()) {
			echo "上一组&nbsp;";
		}
		
		foreach ($pager->group() as $page) {
			echo "<span style='font-size: 12px;'>第{$page}页</span>&nbsp;";
		}
		
		if ($pager->next()) {
			echo "下一组&nbsp;";
			echo "末组(" . $pager->last() . ")";
		}
	}

	private function _sigin() {
		foreach ($_GET as $name => $value) {
			switch ($name) {
				case 'id' :
				case 'name' :
				case 'email' :
				case 'username' :
				case 'password' :
				case 'page' :
					break;
				default :
					unset($_GET[$name]);
			}
		}
		
		if (!isset($_GET['name']) || !$_GET['name']) {
			echo "\$_GET['name'] not null.";
			return FALSE;
		}
		
		if (!isset($_GET['username']) || !$_GET['username']) {
			echo "\$_GET['username'] not null.";
			return FALSE;
		}
		
		return TRUE;
	}

	public function sigin() {
		if (!$this->_sigin()) {
			return FALSE;
		}
		
		if ($this->MMember->sigin($_GET['username'], $_GET['password'], $_GET['name'], $_GET['email'])) {
			$this->assign('name', $_GET['name']);
			$this->assign('username', $_GET['username']);
			$this->assign('display', 'nickname');
			
			$this->assign('member', array('nickname' => 'Nickname', array('sex' => 'Male')));
			
			$this->display();
		} else {
			echo "Failure";
		}
	}
}